const app = getApp()
let qCloud = require("../../../index.js");

Page({
  /** 页面的初始数据 */
  data: {
    imgPath: qCloud.config.STATIC_IMAGE_PATH,
    warehouseList: []
  },

  // 跳转-详情页面
  detailsTap(e) {
    let self = this
    let index = e.currentTarget.dataset.index;
    let enterprise = self.data.warehouseList[index];
    wx.navigateTo({
      url: "/pages/enterprise/warehouse/adds?warehouseId=" + enterprise.warehouseId,
    });
  },

  // 跳转-新增页面
  addsTap(e) {
    wx.navigateTo({
      url: "/pages/enterprise/warehouse/adds",
    });
  },

  /**长按删除*/
  deletedTap: function (e) {
    let self = this;
    wx.showModal({
      content: '确定要删除吗？',
      success(res) {
        if (res.confirm) {
          let params = {
            warehouseId: e.currentTarget.dataset.id
          };
          app.fetchApis(self, qCloud.api.common_deleteWarehouseInfo, params, "POST", function (e) {
            if (e.data.code == 200) {
              self.queryWarehouseList();
            }
          });
        } else if (res.cancel) {
          self.queryWarehouseList();
        }
      }
    })
  },

  /** 生命周期函数--监听页面加载 */
  onLoad: function (options) {
    let self = this;
    // 查询仓库列表
    self.queryWarehouseList();
  },

  /** 查询仓库列表 */
  queryWarehouseList: function (e) {
    let self = this;
    app.fetchApis(self, qCloud.api.common_queryWarehouseList, {}, "POST", function (e) {
      let result = e.data;
      if (result.code == 200) {
        let data = result.data;

        self.setData({
          warehouseList: data.warehouseList
        });
      }
    });
  },

  /** 生命周期函数--监听页面初次渲染完成 */
  onReady: function () {

  },

  /** 生命周期函数--监听页面显示 */
  onShow: function () {
    let self = this;
    self.queryWarehouseList();
  },

  /** 生命周期函数--监听页面隐藏 */
  onHide: function () {

  },

  /** 生命周期函数--监听页面卸载 */
  onUnload: function () {

  },

  /** 页面相关事件处理函数--监听用户下拉动作 */
  onPullDownRefresh: function () {
    let self = this;
    // 查询仓库列表
    self.queryWarehouseList();
  },

  /** 页面上拉触底事件的处理函数 */
  onReachBottom: function () {

  },

  /** 用户点击右上角分享 */
  onShareAppMessage: function () {}
});
